home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE04 / CONSTRUC / TBUUCODE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-09-13  |  2.8 KB  |  97 lines

  1. unit TBUUCode;
  2. interface
  3. uses
  4.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, UUCode;
  5.  
  6. type
  7.   EUUCode = class(Exception);
  8.  
  9.   TUUCode = class(TComponent)
  10.   public
  11.     { Public class declarations (override) }
  12.     constructor Create(AOwner: TComponent); override;
  13.  
  14.   private
  15.     { Private field declarations }
  16.     FInputFileName: String;
  17.     FOutputFileName: String;
  18.  
  19.   protected
  20.     { Protected method declarations }
  21.     function InputFilePChar: PChar;
  22.     function OutputFilePChar: PChar;
  23.  
  24.   public
  25.     { Public interface declarations }
  26.     procedure UUEncode;
  27.     procedure UUDecode;
  28.  
  29.   published
  30.     { Published design declarations }
  31.     property InputFile:  String read FInputFileName write FInputFileName;
  32.     property OutputFile: String read FInputFileName write FInputFileName;
  33.   end;
  34.  
  35. procedure Register;
  36.  
  37. implementation
  38.  
  39.   constructor TUUCode.Create(AOwner: TComponent);
  40.   begin
  41.     if not UUCodeLoaded then raise EUUCode.Create('UUCode.DLL not loaded');
  42.     inherited Create(AOwner);
  43.   end {Create};
  44.  
  45.  
  46.   function TUUCode.InputFilePChar: PChar;
  47.   begin
  48.     FInputFileName[Length(FInputFileName)+1] := #0;
  49.     InputFilePChar := @FInputFileName
  50.   end {InputFilePChar};
  51.  
  52.   function TUUCode.OutputFilePChar: PChar;
  53.   begin
  54.     FOutputFileName[Length(FOutputFileName)+1] := #0;
  55.     OutputFilePChar := @FOutputFileName
  56.   end {OutputFilePChar};
  57.  
  58.  
  59.   procedure TUUCode.UUEncode;
  60.   var Error: Word;
  61.   begin
  62.     if FInputFileName = '' then raise EUUCode.Create('InputFileName is empty');
  63.     if FOutputFileName = '' then raise EUUCode.Create('OutputFileName is empty');
  64.     Error := UUEncoder(InputFilePChar,OutputFilePChar,664,False,nil);
  65.     case Error of
  66.       1: raise EUUCode.Create('UUEnCode: input file is output file');
  67.       2: raise EUUCode.Create('UUEnCode: input file does not exist');
  68.       3: raise EUUCode.Create('UUEnCode: output file exists');
  69.       4: raise EUUCode.Create('UUEnCode: could not create output file');
  70.       5: raise EUUCode.Create('UUEnCode: DLL bussy, try again later (shared buffers)')
  71.     { else OK }
  72.     end
  73.   end {UUEncode};
  74.  
  75.   procedure TUUCode.UUDecode;
  76.   var Error: Word;
  77.   begin
  78.     if FInputFileName = '' then raise EUUCode.Create('InputFileName is empty');
  79.     Error := UUDecoder(InputFilePChar,nil);
  80.     case Error of
  81.       1: raise EUUCode.Create('UUDECode: input file is output file');
  82.       2: raise EUUCode.Create('UUDECode: input file does not exist');
  83.       3: raise EUUCode.Create('UUDECode: output file exists');
  84.       4: raise EUUCode.Create('UUDeCode: could not create output file');
  85.       5: raise EUUCode.Create('UUDeCode: DLL bussy, try again later (shared buffers)')
  86.     { else OK }
  87.     end
  88.   end {UUDecode};
  89.  
  90.  
  91. procedure Register;
  92. begin
  93.   RegisterComponents('Dr.Bob', [TUUCode]);
  94. end {Register};
  95.  
  96. end.
  97.